package com.miniportal.base.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.miniportal.base.mapper.UserBaseInfoMapper;
import com.miniportal.base.pojo.entity.UserBaseInfo;
import com.miniportal.base.pojo.query.UserBaseInfoQuery;
import com.miniportal.base.service.IUserBaseInfoService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户基础信息 服务实现类
 * </p>
 *
 * @author zhouje
 * @since 2022-05-30
 */
@Service
public class UserBaseInfoServiceImpl extends ServiceImpl<UserBaseInfoMapper, UserBaseInfo> implements IUserBaseInfoService {

    @Override
    public List<UserBaseInfo> selectAll() {
        return getBaseMapper().selectList(null);
    }

    @Override
    public int addOne(UserBaseInfo userBaseInfo) {
        return getBaseMapper().insert(userBaseInfo);
    }

    @Override
    public PageInfo<UserBaseInfo> queryUsers(UserBaseInfoQuery request) {
        PageHelper.startPage(request.getPageNumber(),request.getPageSize());
        QueryWrapper<UserBaseInfo> query = new QueryWrapper<>();
        if (StringUtil.isNotEmpty(request.getUserName())) {
            query.eq("user_name", request.getUserName());
        }
        List<UserBaseInfo> userBaseInfos = getBaseMapper().selectList(query);
        PageInfo<UserBaseInfo> result = new PageInfo<>(userBaseInfos);
        return result;
    }
}
